package com.zhongpengcheng.blog.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhongpengcheng.blog.dao.mapper.UserMapper;
import com.zhongpengcheng.blog.dao.pojo.db.UserDO;
import com.zhongpengcheng.blog.service.UserService;
import com.zhongpengcheng.blog.util.TokenUtils;
import org.springframework.stereotype.Service;

/**
 * 用户服务实现类
 * note: 1.记录变更 by zhongpengcheng
 *
 * @author zhongpengcheng
 * @date 2021/08/13 15:35
 **/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, UserDO> implements UserService {

    @Override
    public UserDO getUserByUserName(String userName) {
        return getOne(Wrappers.lambdaQuery(UserDO.class).eq(UserDO::getUsername, userName));
    }

    @Override
    public UserDO getUserByToken(String token) {
        if (TokenUtils.isTokenExpire(token)) {
            return null;
        }
        return UserDO.builder().username("teacher33").password("123").build();
    }

    @Override
    public UserDO getUserByUserId(String userId) {
        return getOne(Wrappers.<UserDO>lambdaQuery().eq(UserDO::getUserId, userId));
    }
}
